package net.hn.hnms.biz.process.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.hn.hnms.biz.process.domain.*;
import net.hn.hnms.biz.process.domain.dto.InspectionCheckDto;
import net.hn.hnms.biz.process.domain.dto.InspectionCheckPoDto;
import net.hn.hnms.biz.process.domain.dto.InspectionConfigDto;
import net.hn.hnms.biz.process.domain.vo.InspectionCheckInfoVo;
import net.hn.hnms.biz.process.domain.vo.InspectionCheckVo;
import net.hn.hnms.biz.process.service.InspectionService;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * 功能描述: 巡检管理
 *
 * @param
 * @auther: WangLong
 * @date: 2022/7/18 13:31
 * @return
 */

@Api(value = "巡检管理控制器", tags = {"巡检管理"})
@RestController
@RequestMapping("inspection")
public class InspectionController {
    @Resource
    private InspectionService inspectionManagementService;



    @ApiOperation("添加巡检管理")
    @PostMapping("config/add")
    @Log(title = "添加巡检管理", businessType = BusinessType.INSERT)
    public R confingAdd(@RequestBody InspectionConfigDto inspectionConfigDto) {
        Boolean is = inspectionManagementService.configAdd(inspectionConfigDto);
        if (is) {
            return R.ok("添加成功");
        }
        return R.fail("添加失败");

    }

    @ApiOperation("修改巡检管理")
    @PutMapping("config/update")
    @Log(title = "修改巡检管理", businessType = BusinessType.UPDATE)
    public R configUpdate(@RequestBody InspectionConfigDto inspectionConfigDto) {
        Boolean is = inspectionManagementService.configUpdate(inspectionConfigDto);
        if (is) {
            return R.ok("修改成功");
        }
        return R.fail("修改失败");

    }

    @ApiOperation("删除巡检管理内容")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @DeleteMapping("/content/delete")
    @Log(title = "删除巡检管理内容", businessType = BusinessType.DELETE)
    public R deleteContent(@RequestBody List<String> idList) {
        Boolean is = inspectionManagementService.deleteContent(idList);
        if (is) {
            return R.ok("删除巡检管理成功");
        }
        return R.fail("删除巡检管理失败");
    }

    @ApiOperation("批量删除巡检管理")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @DeleteMapping("/config/delete")
    @Log(title = "批量删除巡检管理", businessType = BusinessType.DELETE)
    public R deleteConfig(@RequestBody List<String> idList) {
        Boolean is = inspectionManagementService.deleteConfigList(idList);
        if (is) {
            return R.ok("删除巡检管理成功");
        }
        return R.fail("删除巡检管理失败");
    }

    @ApiOperation("分页条件查询巡检管理")
    @GetMapping("config/pageList")
    @AutoSetMineCode
    @Log(title = "查询巡检管理", businessType = BusinessType.OTHER)
    public R<ResponsePage<InspectionConfigDto>> configDelete(PageQuery pageQuery, InspectionConfigPo inspectionConfigPo) {
        if (pageQuery.getPageNum() != null) {
            pageQuery.setPageNum(pageQuery.getPageNum() + 1);
        }
        ResponsePage<InspectionConfigDto> page = inspectionManagementService.configPageList(pageQuery, inspectionConfigPo);
        return R.ok(page);

    }

    @ApiOperation("修改巡检管理状态")
    @PutMapping("/config/update/{id}")
    @Log(title = "修改巡检管理状态", businessType = BusinessType.UPDATE)
    public R chengConfigStatus(@PathVariable String id) {
        Boolean is = inspectionManagementService.chengConfigStatus(id);
        if (is) {
            return R.ok("修改巡检管理成功");
        }
        return R.fail("修改巡检管理失败");
    }

    @ApiOperation("添加巡检检查计划(下发计划)")
    @PostMapping("check/add")
    @Log(title = "添加巡检检查计划(下发计划)", businessType = BusinessType.INSERT)
    public R addCheck(@Validated @RequestBody InspectionCheckPoDto inspectionCheckPoDto) {
        Boolean is = inspectionManagementService.addCheck(inspectionCheckPoDto);
        if (is) {
            return R.ok("添加巡检检查计划成功");
        }
        return R.fail("添加巡检检查计划失败");
    }

    @ApiOperation("删除巡检管理检查计划")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @DeleteMapping("/check/delete")
    @Log(title = "删除巡检管理检查计划", businessType = BusinessType.DELETE)
    public R deleteCheck(@RequestBody List<String> idList) {
        Boolean is = inspectionManagementService.deleteCheck(idList);
        if (is) {
            return R.ok("删除巡检检查计划成功");
        }
        return R.fail("删除巡检检查计划失败");
    }

    @ApiOperation("更新检查计划结果(完成当前检查计划内容)")
    @PutMapping("checkResult/update")
    @Log(title = "更新检查计划结果(完成当前检查计划内容)", businessType = BusinessType.UPDATE)
    public R upDateCheckResult(@RequestBody InspectionCheckResultPo inspectionCheckResultPo, @RequestPart("file") MultipartFile file) {
        Boolean is = inspectionManagementService.upDateCheckResult(inspectionCheckResultPo, file);
        if (is) {
            return R.ok("更新巡检检查计划结果成功");
        }
        return R.fail("更新巡检检查计划结果失败");
    }
    @ApiOperation("修改巡检检查计划)")
    @PutMapping("check/update")
    @Log(title = "修改巡检检查计划", businessType = BusinessType.UPDATE)
    public R upDateCheckResult(@RequestBody InspectionCheckPo inspectionCheckPo) {
        Boolean is = inspectionManagementService.updateCheck(inspectionCheckPo);
        if (is) {
            return R.ok("更新巡检检查计划结果成功");
        }
        return R.fail("更新巡检检查计划结果失败");
    }
    @ApiOperation("修改巡检检查计划结果")
    @PutMapping("result/update")
    @Log(title = "修改巡检检查计划结果", businessType = BusinessType.UPDATE)
    public R upDateCheckResult(@RequestBody List<InspectionCheckInfoVo> inspectionCheckInfoVoList) {
        Boolean is = inspectionManagementService.updateResultList(inspectionCheckInfoVoList);
        if (is) {
            return R.ok("更新巡检检查计划结果成功");
        }
        return R.fail("更新巡检检查计划结果失败");
    }

    @ApiOperation("分页条件查询检查计划列表")
    @GetMapping("check/pageList")
    @AutoSetMineCode
    @Log(title = "查询检查计划列表", businessType = BusinessType.INSERT)
    public R<ResponsePage<InspectionCheckVo>> getCheckList(PageQuery pageQuery, InspectionCheckDto inspectionCheckDto) {
//        pageQuery.setPageNum(pageQuery.getPageNum()+1);
        ResponsePage<InspectionCheckVo> inspectionCheckVoList = inspectionManagementService.checkPageList(pageQuery, inspectionCheckDto);
        return R.ok(inspectionCheckVoList);

    }
    @ApiOperation("我的巡检检查计划")
    @GetMapping("myCheck/pageList")
    @AutoSetMineCode
    @Log(title = "查询我的巡检检查计划", businessType = BusinessType.OTHER)
    public R<ResponsePage<InspectionCheckVo>> getMyCheckList(@ApiParam(value = "煤矿编码") String mineCode) {
        ResponsePage<InspectionCheckVo> inspectionCheckVoList = inspectionManagementService.myCheckPageList(mineCode);
        return R.ok(inspectionCheckVoList);

    }

    /**
     * 功能描述: 根据检查计划ID查询巡检结果内容列表
     *
     * @param id
     * @return net.hn.hnms.sys.common.core.domain.R
     * @auther: WangLong
     * @date: 2022/8/5 13:36
     */

    @ApiOperation("根据检查计划ID查询巡检结果内容列表")
    @GetMapping("result/{id}")
    @Log(title = "检查计划ID查询巡检结果内容列表", businessType = BusinessType.OTHER)
    public R getResultById(@PathVariable String id) {
        List<InspectionCheckInfoVo> inspectionCheckInfoVoList = inspectionManagementService.getResultById(id);
        return R.ok(inspectionCheckInfoVoList);
    }

    /**
     * 功能描述: 根据巡检管理ID查询巡检内容列表
     *
     * @param id
     * @return net.hn.hnms.sys.common.core.domain.R
     * @auther: WangLong
     * @date: 2022/8/5 10:44
     */

    @ApiOperation("根据巡检管理ID查询巡检内容列表")
    @GetMapping("/content/{id}")
    @Log(title = "巡检管理ID查询巡检内容列表", businessType = BusinessType.OTHER)
    public R getContentById(@PathVariable String id) {
        List<InspectionConfigContentPo> inspectionConfigContentPoList = inspectionManagementService.getContentById(id);
        return R.ok(inspectionConfigContentPoList);
    }

    /**
     * 设备管理-新增
     * @param inspectionDevicPo
     * @return
     */
    @ApiOperation("设备管理-新增")
    @PostMapping("/device/add")
    @Log(title = "新增设备管理", businessType = BusinessType.INSERT)
    public R deviceAdd(@RequestBody InspectionDevicPo inspectionDevicPo) {
        Boolean is = inspectionManagementService.deviceAdd(inspectionDevicPo);
        if (is) {
            return R.ok("新增成功");
        }
        return R.fail("新增失败");
    }

    /**
     * 设备管理-修改
     * @param inspectionDevicPo
     * @return
     */
    @ApiOperation("设备管理-修改")
    @PutMapping("/device/update")
    @Log(title = "修改设备管理", businessType = BusinessType.UPDATE)
    public R deviceUpdate(@RequestBody InspectionDevicPo inspectionDevicPo) {
        Boolean is = inspectionManagementService.deviceUpdate(inspectionDevicPo);
        if (is) {
            return R.ok("修改成功");
        }
        return R.fail("修改失败");
    }
    /**
     * 设备管理-批量删除
     * @return
     */
    @ApiOperation("设备管理-批量删除")
    @DeleteMapping("/device/delete")
    @Log(title = "删除设备管理", businessType = BusinessType.DELETE)
    public R deviceDelete(@RequestBody List<String> idList) {
        Boolean is = inspectionManagementService.deviceDelete(idList);
        if (is) {
            return R.ok("删除成功");
        }
        return R.fail("删除失败");
    }

    /**
     * 设备管理-分页查询
     * @param pageQuery
     * @return
     */
    @ApiOperation("设备管理-分页查询")
    @GetMapping("/device/pageList")
    @AutoSetMineCode
    @Log(title = "查询设备管理", businessType = BusinessType.OTHER)
    public R<ResponsePage<InspectionDevicPo>> devicePageList(PageQuery pageQuery,@ApiParam(value = "煤矿编码") String mineCode) {
        pageQuery.setPageNum(pageQuery.getPageNum()+1);
        ResponsePage<InspectionDevicPo> pageList = inspectionManagementService.devicePageList(pageQuery,mineCode);

        return R.ok(pageList);
    }
    @ApiOperation("设备管理-根据ID查询设备详情")
    @GetMapping("/device/{id}")
    @Log(title = "ID查询设备管理", businessType = BusinessType.OTHER)
    public R<InspectionDevicPo> deviceById(@PathVariable(value = "id")String id) {
        InspectionDevicPo inspectionDevicPo = inspectionManagementService.deviceById(id);
        return R.ok(inspectionDevicPo);
    }


}
